/**
 * Created by Bo on 2016/5/12.
 */
var cultureData = {
    home: {'zh-CN': '主页', 'en-US': 'Home'},
    homePage: {'zh-CN': '个人首页', 'en-US': 'Home Page'},
    properties: {'zh-CN': '属性', 'en-US': 'Properties'},
    setting: {'zh-CN': '设置', 'en-US': 'Setting'},
    changePassword: {'zh-CN': '修改密码', 'en-US': 'Change password'},
    logout: {'zh-CN': '退出', 'en-US': 'Logout'},
    changePhoto: {'zh-CN': '更换头像', 'en-US': 'Change Photo'},
    ID: {'zh-CN': 'ID', 'en-US': 'ID'},
    name: {'zh-CN': '名称', 'en-US': 'Name'},
    nickName: {'zh-CN': '昵称', 'en-US': 'Nick Name'},
    loginName: {'zh-CN': '登录名', 'en-US': 'Login Name'},
    password: {'zh-CN': '密码', 'en-US': 'Password'},
    login: {'zh-CN': '登陆', 'en-US': 'login'},
    orgName: {'zh-CN': '组织机构', 'en-US': 'Organization Name'},
    organization: {'zh-CN': '组织机构', 'en-US': 'organization'},
    userManagement: {'zh-CN': '用户管理', 'en-US': 'User Management'},
    orgManagement: {'zh-CN': '组织机构管理', 'en-US': 'Organization Management'},
    email: {'zh-CN': '邮箱', 'en-US': 'Email'},
    phone: {'zh-CN': '手机', 'en-US': 'Phone'},
    operate: {'zh-CN': '操作', 'en-US': 'Operate'},
    userType: {'zh-CN': '用户类型', 'en-US': 'User Type'},
    idcard: {'zh-CN': '身份证号', 'en-US': 'ID Card'},
    sort: {'zh-CN': '排序', 'en-US': 'Sort'},
    save: {'zh-CN': '保存', 'en-US': 'Save'},
    close: {'zh-CN': '关闭', 'en-US': 'Close'},
    selectUser: {'zh-CN': '选择用户', 'en-US': 'Select User'},
    sure: {'zh-CN': '确定', 'en-US': 'Sure'},
    delete: {'zh-CN': '删除', 'en-US': 'Delete'},
    edit: {'zh-CN': '编辑', 'en-US': 'Edit'},
    add: {'zh-CN': '新增', 'en-US': 'Add'},
    status: {'zh-CN': '状态', 'en-US': 'Status'},
    exportTemplate: {'zh-CN': '导出模板', 'en-US': 'Export Template'},
    export: {'zh-CN': '导出', 'en-US': 'Export'},
    nodeType: {'zh-CN': '节点类型', 'en-US': 'Node Type'},
    activityName: {'zh-CN': '节点名称', 'en-US': 'Activity Name'},
    yes: {'zh-CN': '是', 'en-US': 'Yes'},
    no: {'zh-CN': '否', 'en-US': 'No'},
    pleaseselect: {'zh-CN': '请选择', 'en-US': 'Please Select'}
}


var culture = {
    getcultureByKey: function (key) {
        var cc = this.getCulture();
        if (cultureData && cultureData[key] && cultureData[key][cc])
            return cultureData[key][cc];
        return key;
    },

    lanuage: {
        'zh-CN': 0,
        'en-US': 1
    },
    translate: function (body) {
        var me = this;
        var cculture = me.getCulture();
        $("label", body).each(function () {
            var $this = $(this);
            var key = $this.attr('for');
            if (key && cultureData[key] && cultureData[key][cculture]) {
                var value = cultureData[key][cculture];
                $this.html(value);
                var selector = "[name=" + key + "]";
                var input = $(selector).attr('placeholder', value);
            }
        })
        $("*[data-culture]", body).each(function () {
            var $this = $(this);
            var key = $this.data('culture');

            if (cultureData[key] && cultureData[key][cculture]) {
                var value = cultureData[key][cculture];
                if ($this[0].nodeName == 'INPUT') {
                    $this.val(value);
                    $this.attr('data-loading-text', cultureData[key][cculture] + '  ...');
                } else {
                    $this.html(cultureData[key][cculture]);
                }
                if ($this[0].tagName && $this[0].tagName.toLowerCase() == 'label') {
                    $("#" + $this.attr('for')).attr('placeholder', value);
                }
            }
        })

    }, getCulture: function () {
        if ($.cookie('culture'))
            return $.cookie('culture');
        //else return 'en-US';
        else return 'zh-CN';
    }, setCulture: function (c) {
        $.cookie('culture', c);

    }
};

(function () {
    var cculture = culture.getCulture();
    $("#imgFlag").attr('src', cculture == 'zh-CN' ? '/assets/img/flag/en-US.jpg' : '/assets/img/flag/zh-CN.jpg').unbind('click').click(function () {
        culture.setCulture(cculture == 'zh-CN' ? 'en-US' : 'zh-CN');
        window.location = "/index.html";
        //window.location. location.replace(window.location.href);
    });

})();
